package com.vf.admin.miaodong.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppOpLog;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>Title : </p>
 * <p>Description : </p>
 * <p>DevelopTools : IDEA</p>
 * <p>DevelopSystem : Windows11</p>
 *
 * @Author : zxw
 * @Date 2023/8/14 8:53
 */
@Repository
public class AfterOpLogDao extends BaseDao<AppOpLog> {

    /**
     * 综合查询
     *
     * @param map
     * @param splitPage
     */
    public List<AppOpLog> findList(Map<String, Object> map, SplitPageBean splitPage) {
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("");
        sbStr.append(" SELECT a.* FROM app_op_log a where 1=1 ");
        //操作名称
        if (StringEx.isNotNull(map.get("status"))) {
            if (map.get("status").equals(1)) {
                sbStr.append(" and a.opName = ? ");
                paramList.add("注册");
            }
            if (map.get("status").equals(2)) {
                sbStr.append(" and a.opName = ? ");
                paramList.add("登录");
            }
            if (map.get("status").equals(3)) {
                sbStr.append(" and a.opName = ? ");
                paramList.add("一键登录");
            }
            if (map.get("status").equals(4)) {
                sbStr.append(" and a.opName = ? ");
                paramList.add("验证码登录");
            }
            if (map.get("status").equals(5)) {
                sbStr.append(" and a.opName = ? ");
                paramList.add("发朋友圈");
            }
            if (map.get("status").equals(6)) {
                sbStr.append(" and a.opName = ? ");
                paramList.add("完善信息");
            }
            if (map.get("status").equals(7)) {
                sbStr.append(" and a.opName = ? ");
                paramList.add("我的钱包");
            }
            if (map.get("status").equals(8)) {
                sbStr.append(" and a.opName = ? ");
                paramList.add("钻石充值");
            }
            if (map.get("status").equals(9)) {
                sbStr.append(" and a.opName = ? ");
                paramList.add("会员充值");
            }
            if (map.get("status").equals(10)) {
                sbStr.append(" and a.opName = ? ");
                paramList.add("未设置");
            }
        }

        // 设备型号
        if (StringEx.isNotNull(map.get("mobileSpec"))){
            sbStr.append(" and a.mobileSpec = ? ");
            paramList.add(map.get("mobileSpec"));
        }
        // 	用户id
        if (StringEx.isNotNull(map.get("usercode"))){
            sbStr.append(" and a.userId = ? ");
            paramList.add(map.get("usercode"));
        }
        // imei
        if (StringEx.isNotNull(map.get("imei"))){
            sbStr.append(" and a.imei = ? ");
            paramList.add(map.get("imei"));
        }
        if(StringEx.isNotNull(map.get("startDate"))){
            sbStr.append(" and DATE_FORMAT(a.createTime, '%Y-%m-%d')  >=  ? ");
            paramList.add(map.get("startDate"));
        }
        if(StringEx.isNotNull(map.get("endDate"))){
            sbStr.append(" and DATE_FORMAT(a.createTime, '%Y-%m-%d')  <=  ? ");
            paramList.add(map.get("endDate"));
        }
        sbStr.append(" order by a.createTime desc ");
        String sql = sbStr.toString();
        return this.queryList(sql, paramList, AppOpLog.class, splitPage);
    }

}
